 /*
 * @description: 多图拼凑组件
 * @Author: along
 * @Date: 2020-09-08
 * @Last Modified by: along
 * @Last Modified time: 2020-09-11
 */
<template>
    <div
        class="multi"
        @click="emitEvent(2)"
    >
        <!-- 有数据 -->
        <div
            v-if="baseconfig.status"
            class="wrap"
            :style="{background: baseconfig.style.backgroundColor, paddingBottom: baseconfig.style.marginV / 2 + 'px'}"
        >
            <div
                v-for="(option,i) in baseconfig.data.images"
                :key="i"
                class="wrap-list"
                :style="{width: `${(375 - (baseconfig.style.marginH / 2) * (baseconfig.style.columns + 1)) / baseconfig.style.columns}px`, marginLeft: baseconfig.style.marginH / 2 + 'px', marginTop: baseconfig.style.marginV / 2 + 'px', borderRadius: rate}"
            >
                <img
                    :src="option.image_url"
                    :style="{width: '100%', height: '100%', borderRadius: rate}"
                >
            </div>
        </div>
        <!-- 无数据 -->
        <div v-if="!baseconfig.status">
            <img
                src="@/assets/image/multi-none-image.png"
                class="multi-none-image"
            >
            <img
                src="@/assets/image/multi-none-image.png"
                class="multi-none-image"
                :style="{margin: '2px 2px'}"
            >
            <img
                src="@/assets/image/multi-none-image.png"
                class="multi-none-image"
            >
        </div>
    </div>
</template>

<script>
export default {
    name: 'MultiColumn',
    props: {
        baseconfig: {
            type: Object,
            default: () => {}
        },
        index: {//存在多个相同组件,查询当前位置
            type: Number,
            default: () => {}
        }
    },
    data () {
        return {
            rate: '0px 0px 0px 0px'
        };
    },
    watch: {
        //圆角单位转换
        baseconfig:  {
            handler: function (val, oldVal) {
                let rateValue = val.style.borderRadius;

                this.rate = rateValue.replace(/rpx/g, 'px');
            },
            deep: true
        }
    },
    filters: {

    },
    mounted () {
        if(JSON.stringify(this.baseconfig.style) !== '{}') {//回填圆角
            let rateValue = this.baseconfig.style.borderRadius;

            this.rate = rateValue.replace(/rpx/g, 'px');
        }
    },
    methods: {
        /**
         * @description 点击组件，向上级传递点击类型
         */
        emitEvent (type) {
            this.$emit('emit', {
                type: type,//组件类型
                index: this.index//组件位置
            });
        }
    }
};
</script>

<style lang="less" scoped>
.multi {
    width: 375px;
    box-sizing: border-box;
    border: 1px #ffffff solid;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
    //无数据
    .multi-none-image {
        width: 115px;
        height: 170px;
    }
    //有数据
    .wrap {
        width: 375px;
        display: flex;
        flex-wrap: wrap;
    }
}
</style>